package serie07;

import java.awt.Dimension;
import java.util.Observable;

public class StdSwellingModel extends Observable implements SwellingModel {
	
	// ATTRIBUTS
	
	// Dimension du modele
	private Dimension dim;
	
	// CONSTRUCTEUR
	
	public StdSwellingModel() {
		dim = new Dimension(MINIMAL_DIM);
		setChanged();
	}
	
	// REQUETES
    
    public Dimension getDimension() {
    	return dim;
    }
    
    // COMMANDES
    
    public void inflate(double factor) {
    	if (factor < 0) {
    		throw new IllegalArgumentException("Erreur d'accroissement");
    	}
    	double width = Math.min(getDimension().getWidth() * (1 + factor),
    						MAXIMAL_DIM.getWidth());
    	double height = Math.min(getDimension().getHeight() * (1 + factor),
    						MAXIMAL_DIM.getHeight());
    	dim.setSize(width, height);
    	setChanged();
        notifyObservers();
    }
    
    public void deflate(double factor) {
    	if (factor < 0 || factor > 1) {
    		throw new IllegalArgumentException("Erreur lors de la reduction");
    	}
    	double width = Math.max(getDimension().getWidth() * (1 - factor),
				MINIMAL_DIM.getWidth());
    	double height = Math.max(getDimension().getHeight() * (1 - factor),
				MINIMAL_DIM.getHeight());
    	dim.setSize(width, height);
    	setChanged();
        notifyObservers();
    }

}
